package com.xyb.controller;

import com.xyb.entity.CourseDetail;
import com.xyb.service.CourseDetailService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("course-detail")
public class CourseDetailController {
    @Resource
    private CourseDetailService courseDetailService;

    @GetMapping("{courseDetailId}")
    public CourseDetail selectCourseDetailByCourseDetailId(@PathVariable Long courseDetailId){
        return courseDetailService.selectCourseDetailByCourseDetailId(courseDetailId);
    }

    @PostMapping("{chapterId}")
    public String insertCourseDetailByChapterId(@PathVariable Long chapterId, @RequestBody CourseDetail courseDetail){
        courseDetail.setChapterId(chapterId);
        return courseDetailService.insertCourseDetailByChapterId(courseDetail);
    }

    @DeleteMapping("{courseDetailId}")
    public String deleteCourseDetailByCourseDetailId(@PathVariable Long courseDetailId){
        return courseDetailService.deleteCourseDetailByCourseDetailId(courseDetailId);
    }

    @PutMapping("{courseDetailId}")
    public String updateCourseDetailByCourseDetailId(@PathVariable Long courseDetailId, @RequestBody CourseDetail courseDetail){
        courseDetail.setCourseDetailId(courseDetailId);
        return courseDetailService.updateCourseDetailByCourseDetailId(courseDetail);
    }

    @PutMapping("order")
    public String updateCourseDetailShowOrder(@RequestBody Long[] courseDetailIds){
        return courseDetailService.updateCourseDetailShowOrder(courseDetailIds);
    }
}